package com.hb.shopping.service.impl;

import com.hb.shopping.mapper.UserMapper;
import com.hb.shopping.pojo.User;
import com.hb.shopping.pojo.UserExample;
import com.hb.shopping.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author hb
 * @create 2020-04-10 10:43
 */
@Transactional
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public User queryById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<User> queryByLikeName(String name) {
        UserExample example=new UserExample();
        UserExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameLike("%"+name+"%");
         return userMapper.selectByExample(example);
    }

    @Override
    public void deleteById(Integer id) {
        userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insertUser(User user) {
        userMapper.insertSelective(user);
    }


}
